﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraReports.UI;

namespace Wydatki.WRK.Praca.Raporty
{
    public class KpirReport : XtraReport
    {

        private TopMarginBand topMarginBand1;
        private DetailBand detailBand1;
        private BottomMarginBand bottomMarginBand1;

        private void InitializeComponent()
        {
            this.topMarginBand1 = new DevExpress.XtraReports.UI.TopMarginBand();
            this.detailBand1 = new DevExpress.XtraReports.UI.DetailBand();
            this.bottomMarginBand1 = new DevExpress.XtraReports.UI.BottomMarginBand();
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            // 
            // topMarginBand1
            // 
            this.topMarginBand1.Name = "topMarginBand1";
            // 
            // detailBand1
            // 
            this.detailBand1.Name = "detailBand1";
            // 
            // bottomMarginBand1
            // 
            this.bottomMarginBand1.Name = "bottomMarginBand1";
            // 
            // KpirReport
            // 
            this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] {
            this.topMarginBand1,
            this.detailBand1,
            this.bottomMarginBand1});
            this.Version = "10.1";
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();

        }

        private void GetData(int rok, int miesiac)
        {
           string select = @"select  
                W.WRK_KPIR_DATA AS DATA,  
                W.WRK_KPIR_NUMER_DOWODU_KSIEGOWEGO AS NUMER_DOWODU_KSIEGOWEGO,  
                K.STP_KON_NAZWA AS KONTRACHENT_NAZWA,  
                K.STP_KON_ADRES AS KONTRACHENT_ADRES,  
                K.STP_KON_NIP AS KONTRACHENT_NIP,  
                W.WRK_KPIR_OPIS AS OPIS,  
                W.WRK_KPIR_UWAGI AS UWAGI,  
                COALESCE(SUM(K1.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_STIU,  
                COALESCE(SUM(K2.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_PP,  
                COALESCE(SUM(K3.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_ZT,  
                COALESCE(SUM(K4.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_KU,  
                COALESCE(SUM(K5.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_KR,  
                COALESCE(SUM(K6.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_WYN,  
                COALESCE(SUM(K7.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_PW,  
                COALESCE(SUM(K8.WRK_KPIRK_KWOTA_NETTO), 0) AS KWOTA_INNE  
                FROM WRK_KPIR W LEFT JOIN  
                STP_KONTRACHENCI K ON W.WRK_KPIR_KONTRACHENT = K.STP_KON_ID  
                LEFT JOIN WRK_KPIR_KWOTY K1 ON K1.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K1.WRK_KPIRK_TYP = 'STIU'  
                LEFT JOIN WRK_KPIR_KWOTY K2 ON K2.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K2.WRK_KPIRK_TYP = 'PP'  
                LEFT JOIN WRK_KPIR_KWOTY K3 ON K3.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K3.WRK_KPIRK_TYP = 'ZT'  
                LEFT JOIN WRK_KPIR_KWOTY K4 ON K4.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K4.WRK_KPIRK_TYP = 'KU'  
                LEFT JOIN WRK_KPIR_KWOTY K5 ON K5.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K5.WRK_KPIRK_TYP = 'KR'  
                LEFT JOIN WRK_KPIR_KWOTY K6 ON K6.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K6.WRK_KPIRK_TYP = 'WYN'  
                LEFT JOIN WRK_KPIR_KWOTY K7 ON K7.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K7.WRK_KPIRK_TYP = 'PW'  
                LEFT JOIN WRK_KPIR_KWOTY K8 ON K8.WRK_KPIRK_FAKTURA = W.WRK_KPIR_ID AND K8.WRK_KPIRK_TYP = 'INNE'  
                WHERE DATEPART(YEAR, W.WRK_KPIR_DATA) =  @ROK   AND DATEPART(MONTH, W.WRK_KPIR_DATA) =   @MIESIAC
                GROUP BY   
                W.WRK_KPIR_DATA ,  
                W.WRK_KPIR_NUMER_DOWODU_KSIEGOWEGO ,  
                K.STP_KON_NAZWA ,  
                K.STP_KON_ADRES,  
	            K.STP_KON_NIP,
                W.WRK_KPIR_OPIS,  
                W.WRK_KPIR_UWAGI";


        }
    }
}
